package at.sysarch.filter;

import java.io.StreamCorruptedException;
import java.util.ArrayList;
import java.util.List;

import at.pimpmypipe.filter.AbstractSink;
import at.sysarch.bean.AbstractBean;
import at.sysarch.domain.TransferImage;

public class Sink extends AbstractSink<TransferImage> {
	
	private List<Callback> _listeners;
	
	public Sink(AbstractBean<Sink> bean) {
		super(bean);
		_listeners = new ArrayList<Sink.Callback>();
	}

	@Override
	public void write(TransferImage value) throws StreamCorruptedException {
		
		for (Callback callback: _listeners) {
			
			callback.updateResult(value);
		}
	}
	
	public void addListener(Callback listener) {
		
		_listeners.add(listener);
	}
	
	public void removeListener(Callback listener) {
		
		_listeners.remove(listener);
	}

	public interface Callback {
		
		public void updateResult(TransferImage result);
	}
}
